package com.martin.lib_base.binding.adapter

import android.view.View
import android.widget.TextView
import androidx.databinding.BindingAdapter
import dev.utils.app.ViewUtils
import kotlin.math.roundToInt

// "\u3000"
private const val FullSpace = "\u3000"

@BindingAdapter("completeSpace")
fun completeSpace(tv: TextView, count: Int) {
    val s = StringBuilder()
    (1..count).forEach { _ ->
        s.append("一")
    }
    val measureText = tv.paint.measureText(s.toString())
    ViewUtils.setWidth(tv, measureText.roundToInt())
}

/**
 * 补充英文宽度
 */
@BindingAdapter("completeLetterSpace")
fun completeLetterSpace(tv: TextView, count: Int) {
    val s = StringBuilder()
    (1..count).forEach { _ ->
        s.append("A")
    }
    val measureText = tv.paint.measureText(s.toString())
    ViewUtils.setWidth(tv, measureText.roundToInt())
}
